home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * Simple Sample Application Framework
- *
- * ©1991 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * windowstuff.c -- window class instantiation/dispatching
- *
- * change history:
- *
- * SJF 11/7/91 1.0d1 initial coding
- *
- */
-
- #include "const.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "utils.h"
-
- #include "base.window.h"
- #include "dimmer.window.h"
-
- #include "windowstuff.h"
-
- /* gets info handle for a window */
-
- TInfoHndl GetWindowInfo(WindowPtr window)
- {
- TInfoHndl theInfo;
-
- if (window==nil)
- return nil;
-
- theInfo = (TInfoHndl) GetWRefCon(window);
- return theInfo;
- }
-
-
- /* sets info handle for a window */
-
- void SetWindowInfo(WindowPtr window,TInfoHndl info)
- {
- if (window==nil) {
- DoError(kInternalError);
- return;
- }
-
- SetWRefCon (window,(long)info);
- }
-
-
- /* gets window kind of a given window */
-
- WindowKind GetWindowKind(WindowPtr window)
- {
- WindowKind wKind;
-
- if (window==nil) {
- DoError(kInternalError);
- return;
- }
- wKind = ((WindowPeek)window)->windowKind;
- return wKind;
- }
-
-
- /* sets window kind of a given window */
-
- void SetWindowKind(WindowPtr window,WindowKind wKind)
- {
- if (window==nil) {
- DoError(kInternalError);
- return;
- }
-
- wKind += kWindowKindOffset;
- ((WindowPeek)window)->windowKind = wKind;
- }
-
-
- /* checks to see if a window is of a certain type */
-
- Boolean IsWindowType(WindowPtr window,WindowKind type)
- {
- return (type == GetWindowKind(window));
- }
-
-
- /* returns true if it's a window created by the application */
-
- Boolean IsAppWindow(WindowPtr window)
- {
- WindowKind wKind;
-
- if (!window)
- return false;
-
- wKind = GetWindowKind(window);
- return (wKind >= userKind);
- }
-
-
- /* returns true if the window belongs to a DA */
-
- Boolean IsDAWindow(WindowPtr window)
- {
- return (GetWindowKind(window) < 0);
- }
-
-
- /* makes a window of a given type and returns its window pointer */
-
- WindowPtr MakeWindow(WindowKind windowClass,Rect *wRect,StringPtr title,Boolean visible)
- {
- WindowPtr window;
- Rect theRect = kDefaultWindowRect;
-
- if (wRect!=nil)
- theRect = *wRect;
-
- switch (windowClass) {
- case kBaseWindow:
- window = BaseMakeWindow(&theRect,title,visible,documentProc,true);
- break;
- case kDimmerWindow:
- window = DimmerMakeWindow(&theRect,title,visible,8,true);
- break;
- default:
- DoError(kInternalError);
- }
-
- return window;
- }
-
-
- /* sends a message to a given window */
-
- void *SendWindowMessage(WindowPtr window,short msg,void *data)
- {
- TInfoHndl infoHndl;
- char hState;
- MsgProc callProc;
- void *theMsg;
-
- if (!IsAppWindow(window))
- return nil;
-
- infoHndl = GetWindowInfo(window);
- hState = HGetState((Handle)infoHndl);
- HLock((Handle)infoHndl);
-
- switch (msg) {
- case kIdleMessage:
- callProc = (**infoHndl).m_idle;
- break;
- case kFixCursorMessage:
- callProc = (**infoHndl).m_fixCursor;
- break;
- case kActivateMessage:
- callProc = (**infoHndl).m_activate;
- break;
- case kDeactivateMessage:
- callProc = (**infoHndl).m_deactivate;
- break;
- case kUpdateMessage:
- callProc = (**infoHndl).m_update;
- break;
- case kKeyMessage:
- callProc = (**infoHndl).m_key;
- break;
- case kResizeMessage:
- callProc = (**infoHndl).m_resize;
- break;
- case kClickMessage:
- callProc = (**infoHndl).m_click;
- break;
- case kDestroyMessage:
- callProc = (**infoHndl).m_destroy;
- break;
- case kUndoMessage:
- callProc = (**infoHndl).m_undo;
- break;
- case kCutMessage:
- callProc = (**infoHndl).m_cut;
- break;
- case kCopyMessage:
- callProc = (**infoHndl).m_copy;
- break;
- case kPasteMessage:
- callProc = (**infoHndl).m_paste;
- break;
- case kClearMessage:
- callProc = (**infoHndl).m_clear;
- break;
- case kPrintMessage:
- callProc = (**infoHndl).m_print;
- break;
- case kPageSetupMessage:
- callProc = (**infoHndl).m_pageSetup;
- break;
- case kSaveMessage:
- callProc = (**infoHndl).m_save;
- break;
- case kLoadMessage:
- callProc = (**infoHndl).m_load;
- break;
- case kEventMessage:
- callProc = (**infoHndl).m_event;
- break;
- default:
- return;
- }
-
- if (callProc)
- theMsg = (*callProc)(window,*infoHndl,data);
-
- HSetState((Handle)infoHndl,hState);
- return theMsg;
- }
-